<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\BaseController;
use app\lib\exception\BaseException;
use app\model\Admins;

class Login extends BaseController
{

   public function index()
   {
       (new \app\validate\admin\Login())->goCheck();
       $params = request()->param();
       $user = Admins::where('username', $params['username'])->find();
       if (!$user) throw new BaseException(['msg' => '账号或密码错误！', 'errorCode' => 400]);
       if (!password_verify($params['password'], $user->password)) throw new BaseException(['msg' => '账号或密码错误！']);
       $token=createToken($user->id);
       return $this->success(['token'=>$token]);
   }



}
